import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * lovService - 值集视图配置Service
 * @date: 2018-6-26

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, parseParameters, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var urlPrefix = "".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(organizationId, "/") : "/");
/**
 * 查询lov数据
 * @async
 * @function queryLovList
 * @param {object} params - 查询条件
 * @param {?string} params.viewCode - 视图编码
 * @param {?string} params.viewName - 视图名称
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

export function queryLovList(_x) {
  return _queryLovList.apply(this, arguments);
}
/**
 * 保存数据
 * @async
 * @function addLovValue
 * @param {object} params.data - 待保存数据
 * @param {!string} params.data.viewCode - 视图编码
 * @param {!string} params.data.viewName - 视图名称
 * @param {!string} params.data.valueField - valueField
 * @param {!string} params.data.displayField - displayField
 * @param {!string} params.data.lovId - 值集id
 * @param {!number} params.data.delayLoadFlag - 延时标记
 * @param {!number} params.data.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _queryLovList() {
  _queryLovList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var query;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = parseParameters(params);
            return _context.abrupt("return", request("".concat(urlPrefix, "lov-view-headers"), {
              method: 'GET',
              query: query
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryLovList.apply(this, arguments);
}

export function addLovValue(_x2) {
  return _addLovValue.apply(this, arguments);
}
/**
 * 删除数据
 * @async
 * @function deleteLovValue
 * @param {object[]} params.deleteArr - 删除数据集合
 * @param {!string} params.deleteArr[].viewHeaderId - 视图头id
 * @param {!string} params.deleteArr[].objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _addLovValue() {
  _addLovValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(urlPrefix, "lov-view-headers"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _addLovValue.apply(this, arguments);
}

export function deleteLovValue(_x3) {
  return _deleteLovValue.apply(this, arguments);
}
/**
 * 查询lov头数据
 * @async
 * @function queryHeadValue
 * @param {object[]} params.data - 待查询数据
 * @param {!string} params.data.viewHeaderId - 视图头id
 * @returns {object} fetch Promise
 */

function _deleteLovValue() {
  _deleteLovValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(urlPrefix, "lov-view-headers"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deleteLovValue.apply(this, arguments);
}

export function queryHeadValue(_x4) {
  return _queryHeadValue.apply(this, arguments);
}
/**
 * 查询lov行数据
 * @async
 * @function queryLineValue
 * @param {object[]} params.data - 待查询数据
 * @param {!string} params.data.viewHeaderId - 视图头id
 * @param {!number} params.page - 数据页码
 * @param {!number} params.size - 分页大小
 * @returns {object} fetch Promise
 */

function _queryHeadValue() {
  _queryHeadValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(urlPrefix, "lov-view-headers/").concat(params.viewHeaderId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryHeadValue.apply(this, arguments);
}

export function queryLineValue() {
  return _queryLineValue.apply(this, arguments);
}
/**
 * 增加lov行数据
 * @async
 * @function addLineData
 * @param {object[]} params.data - 待保存数据
 * @param {!string} params.data.viewHeaderId - 视图头id
 * @param {!string} params.tenantId - 租户id
 * @param {!number} params.tableFieldWidth - 表格列宽度
 * @param {!number} params.enabledFlag - 启用标志
 * @param {!number} params.queryFieldFlag - 是否查询字段标志
 * @param {!number} params.tableFieldFlag - 是否表格列标志
 * @param {!number} params.orderSeq - 列序号
 * @param {!string} params.fieldName - 表格字段名
 * @param {!string} params.display - 表格字段标题
 * @returns {object} fetch Promise
 */

function _queryLineValue() {
  _queryLineValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var params,
        pagination,
        _args5 = arguments;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
            pagination = parseParameters(params);
            return _context5.abrupt("return", request("".concat(urlPrefix, "lov-view-headers/").concat(params.viewHeaderId, "/lines"), {
              method: 'GET',
              query: pagination
            }));

          case 3:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryLineValue.apply(this, arguments);
}

export function addLineData(_x5) {
  return _addLineData.apply(this, arguments);
}
/**
 * 更新lov行数据
 * @async
 * @function editLine
 * @param {object[]} params.data - 待更新数据
 * @param {!string} params.data.viewHeaderId - 视图头id
 * @param {!string} params.tenantId - 租户id
 * @param {!number} params.tableFieldWidth - 表格列宽度
 * @param {!number} params.enabledFlag - 启用标志
 * @param {!number} params.queryFieldFlag - 是否查询字段标志
 * @param {!number} params.tableFieldFlag - 是否表格列标志
 * @param {!number} params.orderSeq - 列序号
 * @param {!string} params.fieldName - 表格字段名
 * @param {!string} params.display - 表格字段标题
 * @returns {object} fetch Promise
 */

function _addLineData() {
  _addLineData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(urlPrefix, "/lov-view-lines"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _addLineData.apply(this, arguments);
}

export function editLine(_x6) {
  return _editLine.apply(this, arguments);
}
/**
 * 删除数据
 * @async
 * @function removeLine
 * @param {object[]} params.selectedRow - 待删除的数据集合
 * @param {!string} params.selectedRow[].viewLineId - 视图头id
 * @param {!string} params.selectedRow[].objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _editLine() {
  _editLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(urlPrefix, "/lov-view-lines"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _editLine.apply(this, arguments);
}

export function removeLine(_x7) {
  return _removeLine.apply(this, arguments);
}
/**
 * 更新lov头数据
 * @async
 * @function updateHeadValue
 * @param {object} params.data - 待更新数据
 * @param {!string} params.data.viewHeaderId - 视图编码
 * @param {!string} params.data.viewCode - 视图编码
 * @param {!string} params.data.viewName - 视图名称
 * @param {!string} params.data.valueField - valueField
 * @param {!string} params.data.displayField - displayField
 * @param {!string} params.data.lovId - 值集id
 * @param {!number} params.data.delayLoadFlag - 延时标记
 * @param {!number} params.data.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _removeLine() {
  _removeLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(urlPrefix, "lov-view-lines"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _removeLine.apply(this, arguments);
}

export function updateHeadValue(_x8) {
  return _updateHeadValue.apply(this, arguments);
}
/**
 * 根据值集头 ID 查询值集值
 * @param {Object} params - 查询参数
 */

function _updateHeadValue() {
  _updateHeadValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(urlPrefix, "lov-view-headers"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _updateHeadValue.apply(this, arguments);
}

export function copyLovView(_x9) {
  return _copyLovView.apply(this, arguments);
}

function _copyLovView() {
  _copyLovView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(urlPrefix, "lov-view/copy"), {
              method: 'POST',
              body: params,
              query: params
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _copyLovView.apply(this, arguments);
}